import 'package:flutter/material.dart';
import 'package:netstorage/model/CommonModel.dart';
import 'package:netstorage/utils/navigator_utils.dart';

class LocalNavWidget extends StatelessWidget {
  final List<CommonModel>? localNavList;
  const LocalNavWidget({super.key, required this.localNavList});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(7,4,7,4),// padding
      height: 64,
      decoration: const BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(6)),
      ),
      child: Padding(
        padding: const EdgeInsets.all(7),
        child: _items(context),
      ),
    );
  }

  _items(BuildContext context) {
    if(localNavList == null || localNavList?.length == 0) return null;
    List<Widget> items = [];
    for(var model in localNavList!){
      items.add(_item(context, model));
    }
    return Row(children: items, mainAxisAlignment: MainAxisAlignment.spaceBetween,);
  }

  Widget _item(BuildContext context, CommonModel model) {
    return GestureDetector(
      onTap: (){
        print('local_nav_widget跳转到H5地址：${model?.url}');
        NavigatorUtils.jumpH5(url: model?.url ?? '',title: model?.title ?? '');
      },// 点击事件
      child: Column(
        children: [
          Image.network(model.icon!,width: 32, height: 32),
          Text(model.title!, style: const TextStyle(fontSize: 12))
        ],
      ),
    );
  }
}
